package com.yunquan.ohana.ui.calendar.event.search

import androidx.databinding.ObservableField
import com.yunquan.ohana.base.ui.ItemViewModel
import com.yunquan.ohana.entity.ScheduleModel
import java.time.LocalDate
import java.time.format.TextStyle
import java.util.Locale

class EventSearchItemViewModel(viewModel: EventSearchViewModel) : ItemViewModel<EventSearchViewModel>(viewModel) {

    var data: ScheduleModel? = null
    val week = ObservableField<String>()
    val day = ObservableField<String>()
    val title = ObservableField<String>()
    val dateTime = ObservableField<String>()
    val checked = ObservableField(false)
    val isSelect = ObservableField(false)

    constructor(
        viewModel: EventSearchViewModel,
        date:String,
        data: ScheduleModel,
        checked: Boolean = false,
    ) : this(viewModel) {
        this.data = data
        this.title.set(data.title)
        this.checked.set(checked)
        LocalDate.parse(date).let {
            week.set(it.dayOfWeek.getDisplayName(TextStyle.SHORT, Locale.getDefault()))
            day.set(it.dayOfMonth.toString())
        }

        if (data.allDay == 1) {
            this.dateTime.set("All day")
        } else {
            this.dateTime.set("${data.startTimeStr} - ${data.endTimeStr}")
        }
    }
}